package com.etoak.controller;


import com.etoak.common.core.vo.PageVO;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Ingredients;
import com.etoak.service.IngredientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author etoak
 * @since 2025-06-30
 */
@RestController
@RequestMapping("/ingredients")
public class IngredientsController {
    @Autowired
    IngredientsService ingredientsService;

    @PostMapping
    public ResultVO add(@Validated @RequestBody Ingredients ingredients) {
        return ingredientsService.add(ingredients);
    }

    @GetMapping("/list")
    public ResultVO<PageVO<Ingredients>> list(
            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
            Ingredients ingredients) {
        return ingredientsService.listPage(pageNum, pageSize, ingredients);
    }
    @PutMapping("/{id}")
    public ResultVO update(@PathVariable int id, @RequestBody Ingredients ingredients) {
        return ingredientsService.update(id, ingredients);
    }

    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable int id) {
        return ingredientsService.delete(id);
    }

    @GetMapping("/listByType")
    public ResultVO<List<Ingredients>> listByType(String type) {
        return ingredientsService.listByType(type);
    }

}

